package com.doit.demo06;

import java.util.concurrent.locks.Lock;
import java.util.concurrent.locks.ReentrantLock;

@SuppressWarnings("all")
public class tickt implements Runnable {
    private int i=100;

    private Lock lock = new ReentrantLock();
    @Override
    public void run() {
        while(true) {

            lock.lock();
                if (i > 0) {
                    try {
                        Thread.sleep(1);
                        System.out.println(Thread.currentThread().getName() + "正在卖票" + i);
                        i--;
                    } catch (InterruptedException e) {
                        e.printStackTrace();
                    }finally {
                        lock.unlock();
                    }
                }
                else
                {
                    lock.unlock();
                    break;
                }
            }
    }
}
